home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / printer / render.c < prev    next >
C/C++ Source or Header  |  1986-01-15  |  3KB  |  76 lines

  1.  
  2. /*********************************************************************/
  3. /* render.c AmigaLink 1/25/86 */
  4. #include  "exec/types.h"
  5. #include  "exec/nodes.h"
  6. #include  "exec/lists.h"
  7. #include  "exec/memory.h"
  8. #include  "devices/prtbase.h"
  9.  
  10. extern struct PrinterData *PD;
  11.  
  12. /* for the EPSON    */
  13. int Render(ct, x, y, status)
  14. UBYTE ct;   /* null for b/w printers */
  15. UWORD x, y;    /* the x & y co-ordinates */
  16.           /* or the pc & pr print values, or special */
  17. UBYTE status;  /* print status (0-init, 1-enter pixel, 2-dump) */
  18. {
  19.     static UWORD ROWSIZE;
  20.     static UWORD BUFSIZE;
  21.     static UWORD bufptr;
  22.     UWORD i;        /* mics. var */
  23.     BYTE err;       /* the error # */
  24.  
  25.     switch(status)
  26.     {
  27.     case 0 :   /* alloc memory for printer buffer */
  28.      ROWSIZE=x; /* row size required for EPSON */
  29.      BUFSIZE=(6+ROWSIZE); /* buffer size required for EPSON */
  30.      PD->pd_PrintBuf = (UBYTE *)
  31.          AllocMem(BUFSIZE*2,MEMF_PUBLIC); /* alloc public mem */
  32.      if (err=(PD->pd_PrintBuf == 0)) return(err);
  33.      /* reset printer to power-up state */
  34.      if (err=(*(PD->pd_PWrite))("\033@",2)) return(err);
  35.      if (err=PWait(1,0)) return(err);
  36.      if (err=(*(PD->pd_PWrite))("\0331",2)) return(err); /* select 7/72 inch spacing */
  37.      bufptr=0;
  38.      return(0); /* flag all ok */
  39.      break;
  40.  
  41.     case 1 :   /* put pixel in buffer */
  42.      i = bufptr+x+4; /* calc which byte to use */
  43.      PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | (1 << (7-(y&7))); /* fill print buffer */
  44.      return(0); /* flag all ok */
  45.      break;
  46.  
  47.     case 2 : /* dump buffer to printer */
  48.      if (err=(*(PD->pd_PWrite))(&(PD->pd_PrintBuf[bufptr]), BUFSIZE)) return(err);
  49.      bufptr=BUFSIZE-bufptr;
  50.      return(0); /* flag all ok */
  51.      break;
  52.  
  53.     case 3 : /* clear and init buffer */
  54.      for (i=bufptr; i<bufptr+BUFSIZE; i++)
  55.          PD->pd_PrintBuf[i] = 0; /* clear buffer */
  56.      PD->pd_PrintBuf[bufptr] = 27;
  57.      PD->pd_PrintBuf[bufptr+1] = 'L';
  58.      PD->pd_PrintBuf[bufptr+2] = ROWSIZE & 0xff;
  59.      PD->pd_PrintBuf[bufptr+3] = ROWSIZE >> 8;
  60.      PD->pd_PrintBuf[bufptr+BUFSIZE-2] = 10;
  61.      PD->pd_PrintBuf[bufptr+BUFSIZE-1] = 13;
  62.      return(0); /* flag all ok */
  63.      break;
  64.  
  65.     case 4 : /* free the print buffer memory */
  66.      err=(*(PD->pd_PWrite))("\033@",2); /* reset printer to power-up state */
  67.      if (!err) err=(*(PD->pd_PBothReady))(); /* wait for both buffers to empty */
  68.      FreeMem(PD->pd_PrintBuf,BUFSIZE*2); /* free print buffer's memory */
  69.      return(err); /* return status */
  70.      break;
  71.     default: 
  72.      return(0);
  73.     }
  74. }
  75.  
  76.